Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oauth): handle fields missing in the stored config when building consent url #20933

Merged
merged 2 commits into from
Jan 3, 2023

Conversation

pedroslopez
Copy link
Contributor

What

Fixes OC issue https://github.com/airbytehq/oncall/issues/1251

When an input used for the oauth flow is missing from the stored configuration, a java.util.NoSuchElementException: No value present exception was being thrown.

The value not being stored in the database is expected in some scenarios, like is the case for Monday. It has a field located within the oauth credentials block (credentials.subdomain) that would only be set if the connector was previously authenticated with OAuth. Having setting up the connector with an api key, this field is not part of the saved configuration. When the OAuthHandler tries to look up the value for that field, it doesn't find anything and throws the above exception.

How

Update the implementation to only set fields in the returned config that it are present. Fields that are not present in the stored configuration will be left out from the map.

@pedroslopez pedroslopez requested review from a team and alafanechere December 30, 2022 06:28
@octavia-squidington-iv octavia-squidington-iv added area/platform issues related to the platform area/server labels Dec 30, 2022
@pedroslopez pedroslopez temporarily deployed to more-secrets December 30, 2022 17:50 — with GitHub Actions Inactive
@pedroslopez pedroslopez temporarily deployed to more-secrets December 30, 2022 17:52 — with GitHub Actions Inactive
entry -> JsonPaths.getSingleValue(hydratedSourceConnectionConfiguration, entry.getValue()).get())));
final Map<String, JsonNode> result = new HashMap<>();
pathsToGet.forEach((k, v) -> {
final Optional<JsonNode> configValue = JsonPaths.getSingleValue(hydratedSourceConnectionConfiguration, v);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead make sure the hydratedSourceConnectionConfiguration has all the expected paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected behavior is actually that hydratedSourceConnectionConfiguration doesn't have the path we're trying to get in this case.

Because of the way the spec is defined, credentials.subdomain is only present in the config if the OAuth authentication type has been selected (since it's only used in the oauth case)

So, if you're coming from an API key auth, your config will look something like {"credentials": {"api_token": "sometoken", "auth_type": "api_token"}}. When this method runs after switching for oauth, we try to get the value of credentials.subdomain from the existing configuration but realize it's not there. Previously since we always expected it to be present an error would be thrown. Now, we just log a warning and don't retrieve the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants